﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoForChessFromTC
{ 
    /// <summary>
    /// 块的状态
    /// </summary>
    enum BlockStatus   //枚举定义块的三种状态
    {
        Blank,  //空白
        Black,  //黑子
        White   //白子
    }

    /// <summary>
    /// 块对象
    /// </summary>
    class Block
    {
        /// <summary>
        /// 状态
        /// </summary>
        public BlockStatus Status { get; set; }
        //用get set方法来访问（get)修改（set)私有成员变量

        // <summary>
        /// 矩阵坐标
        /// </summary>
        public Point Point { get; set; }
        //用get set方法访问（get)修改（set)私有成员变量

        private Rectangle Rectangle
        {
            get{return new Rectangle(Point.Y * 100 + 100, Point.X * 100 + 100, 100, 100); }
            //这里的Point.Y,Point.X为方格坐标标记（可认为缩为一个点）
            //而rectangle的坐标（新x新y）及大小是把原扩合适倍数
            //这里包含相当于有一句Rectangle Rectangle=new Rectangle(Point.Y * 100 + 100, Point.X * 100 + 100, 100, 100)
        }

        public Block()
        {
            //初始状态为空白
            Status = BlockStatus.Blank;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="point">矩阵坐标（与物理坐标反）</param>
        public Block (Point point)//多态，有坐标的
        {
            //初始状态为空白
            Status = BlockStatus.Blank;
            Point = point;
        }
        /// <summary>
        /// 画出当前格子
        /// </summary>
        /// <param name="g">画图句柄</param>
        public void Draw(Graphics g)    //在Game里被调用
        {
            //绘制深浅区域（在上面定好尺寸的rectangle里）
            if ((Point.Y+Point.X) % 2 ==0 )
                //由坐标特征，深色区横纵坐标加和为偶数
                g.DrawImage(Properties.Resources.dark_bg, Rectangle);
            else
                //浅色区横纵坐标加和为奇数
                g.DrawImage(Properties.Resources.light_bg, Rectangle);
            //dark_bg为深色图，light_bg为浅色图

            switch (Status)
            {
                //根据变量block的状态，也在对应rectangle里绘制该状态下的棋子图案
                case BlockStatus.Black:
                    g.DrawImage(Properties.Resources.black_piece, Rectangle);
                    break;
                case BlockStatus.White:
                    g.DrawImage(Properties.Resources.white_piece, Rectangle);
                    break;
                    // black_piece,white_piece分别为黑子，白子图
            }
        }

    }
}
